package controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 处理退出应用程序的请求
 * @author cqyhm
 *
 */
@WebServlet(urlPatterns= "/logout.do")
public class LogoutServlet extends HttpServlet {

	private static final long serialVersionUID = 8635771039836398497L;
	private Logger logger=LoggerFactory.getLogger(getClass());
	
	/**
	 * 处理get方法发送过来的请求
	 */
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	/**
	 * 处理post方法发送过来的请求
	 */
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		logger.info("logout.dopost");
		HttpSession session=req.getSession();
		session.invalidate();
		resp.sendRedirect(req.getContextPath()+"/login.jsp");
		logger.info("退出登录成功");
		//1.接收前台传递过来的参数
		//2.参数类型转换
		//3.参数合法性校验
		//4.参数封装为对象
		//5.调用业务方法
		//6.转发或重定向(可传递数据给页面)
	}

}
